package com.example.demo.services.impl;

import com.example.demo.dao.HWRepository;
import com.example.demo.entity.HW;
import com.example.demo.services.HWService;
import com.example.demo.services.HWService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HWServiceImpl implements HWService {

    @Autowired
    private HWRepository hwRepository;

    /**
     * @Author: Ding XiJie
     * @Description: 添加员工
     */
    @Override
    public HW save(HW hw) {
        hw = hwRepository.save(hw);
        return hw;
    }

    /**
     * @Author: Ding XiJie
     * @Description: 修改员工
     */
    @Override
    public HW update(HW hw) {
        return hwRepository.save(hw);
    }

    /**
     * @Author: Ding XiJie
     * @Description: 删除员工
     */
    @Override
    public void delete(int id) {
        hwRepository.deleteById(id);
    }

    @Override
    public List<HW> getAllHw() {
        return hwRepository.findAll();
    }

    @Override
    public Integer findCount() {
        Long count = hwRepository.count();
        Integer countInt = count.intValue();
        return countInt;
    }
}
